/*
  This rank is part of 'Trivial chess'.

  'Trivial chess' is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  'Trivial chess' is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with 'Trivial chess'.  If not, see <http://www.gnu.org/licenses/>.
*/

/* SVN RANK: $Id$ */
/**
 * @author         $Author$
 * @version        $Rev$
 * @lastrevision   $Date$
 * @ranksource     $URL$
 */

//#define BOOST_TEST_MODULE Rank
#include <boost/test/unit_test.hpp>
#include "../config.h"


BOOST_AUTO_TEST_SUITE( RankTest )

const Rank RANKS[] = {
		Rank::R1(),
		Rank::R2(),
		Rank::R3(),
		Rank::R4(),
		Rank::R5(),
		Rank::R6(),
		Rank::R7(),
		Rank::R8(),
		Rank::NIL()
	};

const char* RANKS_STR[] = {"1","2","3","4","5","6","7","8","-"};

const int RANKS_LENGTH = 9;

BOOST_AUTO_TEST_CASE( testEqual ) {
	for ( int i = 0; i < RANKS_LENGTH; ++i ) {
		Rank rank = RANKS[i];
		BOOST_CHECK_EQUAL(rank, RANKS[i]);
	}
}

BOOST_AUTO_TEST_CASE( testNotEqual ) {
	for ( int i = 0; i < RANKS_LENGTH; ++i ) {
		Rank rank1 = RANKS[i];
		for ( int j = 0; j < 7; ++j ) {
			Rank rank2 = RANKS[j];
			if ( i != j )
				BOOST_CHECK_NE(rank1, rank2);
		}
	}
}

BOOST_AUTO_TEST_CASE( testToInt ) {
	for ( int i = 0; i < RANKS_LENGTH; ++i ) {
		Rank rank = RANKS[i];
		BOOST_CHECK_EQUAL(rank.toInt(), i);
	}
}

BOOST_AUTO_TEST_CASE( testFromInt ) {
	for ( int i = 0; i < RANKS_LENGTH; ++i ) {
		Rank rank;
		rank.fromInt(i);
		BOOST_CHECK_EQUAL(rank, RANKS[i]);
	}
}

BOOST_AUTO_TEST_CASE( testRank_Int ) {
	for ( int i = 0; i < RANKS_LENGTH; ++i ) {
		Rank rank = Rank(i);
		BOOST_CHECK_EQUAL(rank, RANKS[i]);
	}
}

BOOST_AUTO_TEST_CASE( testInc ) {
	int i = 0;
	Rank rank = Rank::BEGIN();
	while ( i < RANKS_LENGTH - 1 ) {
		BOOST_CHECK_EQUAL(RANKS[i], rank);
		++rank;
		++i;
	}
	BOOST_CHECK_EQUAL(rank, Rank::END());
}

BOOST_AUTO_TEST_CASE( testDec ) {
	int i = RANKS_LENGTH - 2;
	Rank rank = Rank::RBEGIN();
	while ( i >= 0 ) {
		BOOST_CHECK_EQUAL(RANKS[i], rank);
		--rank;
		--i;
	}

	BOOST_CHECK_EQUAL(rank, Rank::REND());
}

BOOST_AUTO_TEST_CASE( testToStr ) {
	for ( int i = 0; i < RANKS_LENGTH; ++i ) {
		Rank rank = RANKS[i];

		BOOST_CHECK_EQUAL(rank.toStr(), RANKS_STR[i]);
	}
}

BOOST_AUTO_TEST_CASE( testFromStr ) {
	for ( int i = 0; i < RANKS_LENGTH; ++i ) {
		Rank rank;
		rank.fromStr(RANKS_STR[i]);

		BOOST_CHECK_EQUAL(rank, RANKS[i]);
	}
}

BOOST_AUTO_TEST_CASE( testLast ) {
	BOOST_CHECK_EQUAL(Rank::last(Color::WHITE()), Rank::R8());
	BOOST_CHECK_EQUAL(Rank::last(Color::BLACK()), Rank::R1());
}

BOOST_AUTO_TEST_CASE( testFirst ) {
	BOOST_CHECK_EQUAL(Rank::first(Color::WHITE()), Rank::R1());
	BOOST_CHECK_EQUAL(Rank::first(Color::BLACK()), Rank::R8());
}


BOOST_AUTO_TEST_SUITE_END()
